package com.example.springbootmybatis.common;

import lombok.Data;

import java.util.List;

/**
 * @author cuikaixuan
 * @date 2021/4/23  10:21
 * @desc 分页返回结果
 */
@Data
public class PageResult<T> {
    private int pageIndex;//当前页

    private int pageSize;//每页条数

    private Long totalCount;//符合查询条件总条数

    private List<T> pageData;//符合查询条件的列表_注意这里是泛型

    private int startRow;//数据库起始记录指针(分页)

    private int totalPage;//总页数

    public PageResult(int pageIndex, int pageSize){
        this.pageIndex = pageIndex <= 0 ? 1 : pageIndex;
        this.pageSize = pageSize <= 0 ? 10 : pageSize;
    }
    public int getTotalPage() {
        totalPage = (int) Math.ceil(totalCount/Double.parseDouble(String.valueOf(pageSize)));
        return totalPage;
    }
    public int getStartRow() {
        startRow = (pageIndex-1) * pageSize;
        return startRow;
    }
}
